package com.mlethe.android.demo.seattable.model;

import com.mlethe.android.demo.seattable.api.ServiceApi;
import com.mlethe.android.demo.seattable.entity.CineSeat;
import com.mlethe.android.demo.seattable.entity.Hall;
import com.mlethe.android.demo.seattable.entity.Obj;
import com.mlethe.android.demo.seattable.entity.Result;
import com.mlethe.library.net.RestClient;
import com.mlethe.library.utils.SortUtil;

import java.util.HashMap;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class MovieModel {

    /**
     * 获取放映计划列表
     * @param map
     * @return
     */
    public Observable<Result<Obj<List<Hall>>>> cinemaPlays(HashMap<String, Object> map) {
        return RestClient.getInstance()
                .create(ServiceApi.class)
                .cinemaPlays(getCidAndPid(map))
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    /**
     * 获取某（几）个场次信息
     * @param map
     * @return
     */
    public Observable<Result<Obj<List<Hall>>>> cinemaPlayInfo(HashMap<String, Object> map) {
        return RestClient.getInstance()
                .create(ServiceApi.class)
                .cinemaPlayInfo(getCidAndPid(map))
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    /**
     * 获取某场次座位状态
     * @param map
     * @return
     */
    public Observable<Result<Obj<List<CineSeat>>>> cinemaPlaySeatStatus(HashMap<String, Object> map) {
        return RestClient.getInstance().create(ServiceApi.class)
                .cinemaPlaySeatStatus(getCidAndPid(map))
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    private String getCidAndPid(HashMap<String, Object> map) {
        map.put("format", "json");
        map.put("pid", 11191);
        map.put("cid", 20005013);
//        map.put("pid", 90134);
//        map.put("cid", 11);
        return SortUtil.sortToStringByASCLL(map);
    }

}
